//
//  RORegisterViewController.swift
//  NeuFood
//
//  Created by yangjingxin on 2017/10/12.
//  Copyright © 2017年 yangjingxin. All rights reserved.
//

import UIKit

class RORegisterViewController: UIViewController {

    @IBOutlet weak var username: UITextField!
    
    @IBOutlet weak var userpass: UITextField!
    
    @IBOutlet weak var mobilenum: UITextField!
    
    @IBOutlet weak var address: UITextField!
    
    @IBOutlet weak var comment: UITextField!
    
    @IBAction func submit(_ sender: UIButton) {
    
    if username.text == ""{
    //print("用户名没有输入")
    MBProgressHUD.showDelayHUDToView(self.view, message: "用户名没有输入")
    
    }else if userpass.text == ""{
    //print("密码没有输入")
    MBProgressHUD.showDelayHUDToView(self.view, message: "密码没有输入")
    }
    else if mobilenum.text == ""{
    //print("密码没有输入")
    MBProgressHUD.showDelayHUDToView(self.view, message: "电话没有输入")
    }
    else if address.text == ""{
    //print("密码没有输入")
    MBProgressHUD.showDelayHUDToView(self.view, message: "地址没有输入")
    }
    else if comment.text == ""{
    //print("密码没有输入")
    MBProgressHUD.showDelayHUDToView(self.view, message: "备注没有输入")
    }
    
    
    let parameters:NSDictionary = ["username": self.username.text!,"userpass": self.userpass.text!,"mobilenum": self.mobilenum.text!,"address":self.address.text!,"comment": self.comment.text!] as NSDictionary
    
    let afManager = AFHTTPRequestOperationManager()
    afManager.get("http://60.205.189.39/userRegister.do", parameters: parameters, success: { (operation:AFHTTPRequestOperation?,responseObject: Any?) in
    //print(responseObject)
    let success = (responseObject as! NSDictionary).object(forKey: "success") as! NSString
    
    if success == "1"{
    //print("登录成功")
    MBProgressHUD.showDelayHUDToView(self.view, message: "注册成功")
    
    
    }else{
    //print("登录失败")
    MBProgressHUD.showDelayHUDToView(self.view, message: "注册失败")
    
    }
    
    }){(operation: AFHTTPRequestOperation?, error:Error?) in
    /* RONetworkMngTool.sharedNetworkMngTool().RONetwork_Rrgister(parameters, view: self.view)
     {
     (flag) -> Void in
     if flag == "1"{
     let _ = self.navigationController?.popViewController(animated: true)}
     else{
     
     }
     } */
    
    
    }
}


override func viewDidLoad() {
    super.viewDidLoad()
    
    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
 // MARK: - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
 // Get the new view controller using segue.destinationViewController.
 // Pass the selected object to the new view controller.
 }
 */



}
